package itsm.isperp.framework.web.json;

import itsm.isperp.framework.data.mybatis.plugin.JqGridResponseData;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2014-5-6
 * @since 1.0
 * 
 */
@SuppressWarnings("rawtypes")
public class JqGridResponseDataJsonSerializer extends
		JsonSerializer<JqGridResponseData> {
	@Override
	public void serialize(JqGridResponseData value, JsonGenerator jgen,
			SerializerProvider provider) throws IOException,
			JsonProcessingException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("page", value.getNumber());
		map.put("total", value.getTotalPages());
		map.put("records", value.getTotalElements());
		map.put("content", value.getContent());
		ObjectMapper mapper = new ObjectMapper();
		mapper.writeValue(jgen, map);
	}

}
